package com.mall.controller;

import com.mall.domain.ItemGoods;
import com.mall.service.IGoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("goods")
public class GoodsDetailController {
    @Autowired
    private IGoodsDetailService iGoodsDetailService;

    /**
     查询商品详细信息
     */
    @RequestMapping("/findGoodsDetail")
    public  @ResponseBody
    Map<String,Object> getGoods() {
        Map<String,Object> msgMap = new HashMap<>();
        Map<String,Object> map = new HashMap<>();
        //获取商品类别集合
        Integer goods_id = 7;
        ItemGoods goodsDetail = iGoodsDetailService.findGoodsDetail(goods_id);
        //放入Map集合
        msgMap.put("message",goodsDetail);

        //创建状态Map
        Map<String,Object> metaMap = new HashMap<>();
        metaMap.put("msg","获取商品类别列表成功");
        metaMap.put("status",200);

        map.put("message",msgMap);
        msgMap.put("meta",metaMap);
        return map;
    }
    /**
     搜索商品
     */
    @RequestMapping("/findItemGoodsByName")
    public  @ResponseBody
    Map<String,Object> findItemGoodsByName(HttpServletRequest request) {
        Map<String,Object> msgMap = new HashMap<>();
        Map<String,Object> map = new HashMap<>();
        String name = request.getParameter("name");
        //获取商品类别集合
//        Integer goods_id = 7;
        List<ItemGoods> goodsDetail = iGoodsDetailService.findItemGoodsByName(name);
        //放入Map集合
        msgMap.put("message",goodsDetail);

        //创建状态Map
        Map<String,Object> metaMap = new HashMap<>();
        metaMap.put("msg","搜索商品类别列表成功");
        metaMap.put("status",200);

        map.put("message",msgMap);
        msgMap.put("meta",metaMap);
        return map;
    }


}
